Weave는 다음을 통해 이루어진 LLM 호출을 자동으로 추적하고 기록합니다 Cerebras Cloud SDK.

Traces

LLM 호출 추적은 디버깅 및 성능 모니터링에 중요합니다. Weave는 Cerebras Cloud SDK에 대한 트레이스를 자동으로 캡처하여 이를 수행하는 데 도움을 줍니다. 다음은 Weave를 Cerebras와 함께 사용하는 예시입니다:
import os
import weave
from cerebras.cloud.sdk import Cerebras

# Initialise the weave project
weave.init("cerebras_speedster")

# Use the Cerebras SDK as usual
api_key = os.environ["CEREBRAS_API_KEY"]
model = "llama3.1-8b"  # Cerebras model

client = Cerebras(api_key=api_key)

response = client.chat.completions.create(
    model=model,
    messages=[{"role": "user", "content": "What's the fastest land animal?"}],
)

print(response.choices[0].message.content)
이제 Weave는 Cerebras SDK를 통해 이루어진 모든 LLM 호출을 추적하고 기록합니다. Weave 웹 인터페이스에서 토큰 사용량 및 응답 시간과 같은 세부 정보를 포함한 트레이스를 볼 수 있습니다. cerebras_calls.png

자체 ops로 래핑하기

Weave ops는 실험의 재현성과 추적성을 향상시키는 강력한 방법을 제공합니다. 코드를 자동으로 버전 관리하고 입력 및 출력을 캡처합니다. 다음은 Cerebras SDK와 함께 Weave ops를 활용하는 방법의 예시입니다:
import os
import weave
from cerebras.cloud.sdk import Cerebras

# Initialise the weave project
weave.init("cerebras_speedster")

client = Cerebras(api_key=os.environ["CEREBRAS_API_KEY"])

# Weave will track the inputs, outputs and code of this function
@weave.op
def animal_speedster(animal: str, model: str) -> str:
    "Find out how fast an animal can run"
    
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": f"How fast can a {animal} run?"}],
    )
    return response.choices[0].message.content

animal_speedster("cheetah", "llama3.1-8b")
animal_speedster("ostrich", "llama3.1-8b")
animal_speedster("human", "llama3.1-8b")

더 쉬운 실험을 위한 Model 생성

Weave의 Model 클래스는 앱의 다양한 반복을 구성하고 비교하는 데 도움이 됩니다. 이는 Cerebras 모델로 실험할 때 특히 유용합니다. 다음은 예시입니다:
import os
import weave
from cerebras.cloud.sdk import Cerebras

# Initialise the weave project
weave.init("cerebras_speedster")

client = Cerebras(api_key=os.environ["CEREBRAS_API_KEY"])

class AnimalSpeedModel(weave.Model):
    model: str
    temperature: float

    @weave.op
    def predict(self, animal: str) -> str:
        "Predict the top speed of an animal"        

        response = client.chat.completions.create(
            model=self.model,
            messages=[{"role": "user", "content": f"What's the top speed of a {animal}?"}],
            temperature=self.temperature
        )
        return response.choices[0].message.content

speed_model = AnimalSpeedModel(
    model="llama3.1-8b",
    temperature=0.7
)
result = speed_model.predict(animal="cheetah")
print(result)
이 설정을 통해 Cerebras 기반 추론을 추적하면서 다양한 모델과 매개변수로 쉽게 실험할 수 있습니다! cerebras_model.png